use std::{fs};
use serde_derive::Deserialize;

use serde_yaml::from_reader;
#[derive(Deserialize,Debug)]
pub struct Config {
    pub mongodb:Mongdb
}

#[derive(Deserialize,Debug)]
pub struct Mongdb{
    pub db_url:String,
    pub db_name:String,
}

impl Config {
    pub fn init(path:&str) -> Config {
            let config_text = fs::read_to_string(path).unwrap();

            let config:Config = from_reader(&mut config_text.as_bytes()).unwrap();

            config
    }
}

fn main() {
    println!("Hello, world!");
    let app_config_path = "./app.yaml";
    let appconfig:Config = Config::init(app_config_path);
    println!("{:?}", appconfig);
    println!("{:?}", appconfig.mongodb.db_name);
}

